import {createBrowserRouter, Navigate} from "react-router-dom";
import {Suspense, lazy} from 'react'
import Layout from "../layout";
import Login from "../view/login";
import AuthRoute from "@/component/auth-route";

const Home = lazy(() => import('@/view/home'))
const Article = lazy(() => import('@/view/article'))
const Publish = lazy(() => import('@/view/publish'))

export const router = createBrowserRouter([
    {
        path: '/',
        element: <AuthRoute><Layout /></AuthRoute>,
        children: [
            {
                path: 'home',
                element: <Suspense fallback={'加载中'}><Home /></Suspense>
            },
            {
                path: 'article',
                element: <Suspense fallback={'加载中'}><Article /></Suspense>
            },
            {
                path: 'publish',
                element: <Suspense fallback={'加载中'}><Publish /></Suspense>
            },
            {
                path: '/',
                element: <Navigate to='/home' />
            }
        ]
    },
    {
        path: '/login',
        element: <Login />
    }
])
